\ProvidesPackage{styles/references}

% Easily label and reference elements
% Note that \label must appear after \caption
% hyperref is already loaded
\usepackage{varioref}
%\usepackage{cleveref} % Don't use cleveref! It breaks everything
\newcommand{\sectionname}{Section}

\newcommand{\labpage}[1]{\label{page:#1}}
\newcommand{\labpart}[1]{\label{part:#1}}
\newcommand{\labch}[1]{\label{ch:#1}}
\newcommand{\labsec}[1]{\label{sec:#1}}
\newcommand{\labfig}[1]{\label{fig:#1}}
\newcommand{\labtab}[1]{\label{tab:#1}}
\newcommand{\labdef}[1]{\label{def:#1}}
\newcommand{\labthm}[1]{\label{thm:#1}}
\newcommand{\labprop}[1]{\label{prop:#1}}
\newcommand{\lablemma}[1]{\label{lemma:#1}}
\newcommand{\labremark}[1]{\label{remark:#1}}
\newcommand{\labexample}[1]{\label{example:#1}}
\newcommand{\labexercise}[1]{\label{exercise:#1}}

\newcommand{\refpage}[1]{\hyperref[#1]{第}\pageref{page:#1}\hyperref[#1]{页}} % Page 84
\newcommand{\vrefpage}[1]{\vpageref*{page:#1}} % on the following page, on page 84

\newcommand{\refpart}[1]{\hyperref[part:#1]{第}\ref{part:#1}\hyperref[part:#1]{部分}} % Part IV
\newcommand{\vrefpart}[1]{\hyperref[part:#1]{第}\ref{part:#1}\hyperref[part:#1]{部分}} % Part IV, Part IV on the following page, Part IV on page 84
\newcommand{\nrefpart}[1]{\hyperref[part:#1]{第}\ref{part:#1}\hyperref[part:#1]{部分} (\nameref{part:#1})}
\newcommand{\frefpart}[1]{\hyperref[part:#1]{第\ref{part:#1}\hyperref[part:#1]{部分} (\nameref{part:#1}) 第\pageref{part{#1}}页}} % Part IV (Name of the Part), Part IV (Name of the Part) on the following page, Part IV (Name of the Part) on page 84)

%\newcommand{\refch}[1]{\hyperref[#1]{\chaptername~\usekomafont{chapter}\normalsize\nameref{ch:#1}}\xspace\vpageref{ch:#1}\,}
\newcommand{\refch}[1]{\hyperref[ch:#1]{第\ref{ch:#1}章}}
\newcommand{\vrefch}[1]{\hyperref[ch:#1]{第\ref{ch:#1}章}}
\newcommand{\nrefch}[1]{\hyperref[ch:#1]{第\ref{ch:#1}章 (\nameref{ch:#1})}}
\newcommand{\frefch}[1]{\hyperref[ch:#1]{第\ref{ch:#1}章 (\nameref{ch:#1}) 第\pageref{ch:#1}页}}

%\newcommand{\refsec}[1]{Section~{\usekomafont{section}\normalsize\nameref{sec:#1}}\xspace\vpageref{sec:#1}\,}
\newcommand{\refsec}[1]{\hyperref[sec:#1]{第\ref{sec:#1}节}}
\newcommand{\vrefsec}[1]{\hyperref[sec:#1]{第\ref{sec:#1}节}}
\newcommand{\nrefsec}[1]{\hyperref[sec:#1]{第\ref{sec:#1}节 (\nameref{sec:#1})}}
\newcommand{\frefsec}[1]{\hyperref[sec:#1]{第\ref{sec:#1}节 (\nameref{sec:#1}) 第\pageref{sec:#1}页}}

%\newcommand{\reffig}[1]{{\hypersetup{colorlinks=false}\usekomafont{captionlabel}\hyperref[fig:#1]{Figure}\xspace\ref{fig:#1}}}
\newcommand{\reffig}[1]{\hyperref[fig:#1]{图}\xspace\ref{fig:#1}}
\newcommand{\vreffig}[1]{\hyperref[fig:#1]{图\xspace\vref{fig:#1}}}

%\newcommand{\reftab}[1]{{\hypersetup{colorlinks=false}\usekomafont{captionlabel}\hyperref[tab:#1]{Table}\xspace\ref{tab:#1}}}
\newcommand{\reftab}[1]{\hyperref[tab:#1]{表}\xspace\ref{tab:#1}}
\newcommand{\vreftab}[1]{\hyperref[tab:#1]{表\xspace\vref{tab:#1}}}

\newcommand{\refdef}[1]{\hyperref[def:#1]{定义}\xspace\ref{def:#1}}
\newcommand{\vrefdef}[1]{\hyperref[def:#1]{定义}\xspace\vref{def:#1}}

\newcommand{\refthm}[1]{\hyperref[thm:#1]{定理}\xspace\ref{thm:#1}}
\newcommand{\vrefthm}[1]{\hyperref[thm:#1]{定理}\xspace\vref{thm:#1}}

\newcommand{\refprop}[1]{\hyperref[prop:#1]{命题}\xspace\ref{prop:#1}}
\newcommand{\vrefprop}[1]{\hyperref[prop:#1]{命题}\xspace\vref{prop:#1}}

\newcommand{\reflemma}[1]{\hyperref[lemma:#1]{引理}\xspace\ref{lemma:#1}}
\newcommand{\vreflemma}[1]{\hyperref[lemma:#1]{引理}\xspace\vref{lemma:#1}}

\newcommand{\refremark}[1]{\hyperref[remark:#1]{备注}\xspace\ref{remark:#1}}
\newcommand{\vrefremark}[1]{\hyperref[remark:#1]{备注}\xspace\vref{remark:#1}}

\newcommand{\refexample}[1]{\hyperref[example:#1]{例}\xspace\ref{example:#1}}
\newcommand{\vrefexample}[1]{\hyperref[example:#1]{例}\xspace\vref{example:#1}}

\newcommand{\refexercise}[1]{\hyperref[exercise:#1]{练习}\xspace\ref{exercise:#1}}
\newcommand{\vrefexercise}[1]{\hyperref[exercise:#1]{练习}\xspace\vref{exercise:#1}}
